/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ieslaferreria.creditsintesis.controllers;

import edu.ieslaferreria.creditsintesis.logicgame.ActionStates;
import edu.ieslaferreria.creditsintesis.logicgame.MobilObject;
import edu.ieslaferreria.creditsintesis.logicgame.ObjectWithStates;
import java.util.Iterator;

/**
 * controla las colisiones entre los objetos. Implementamos la clase abstracta.
 * @author Rubén
 */
public class SimpleCollisionController extends CollisionController{

    public SimpleCollisionController(ActionStates as)  {
        super(as);
    }



//

/**
 * valida y cambia estado pasando un activador (ture commit y false rollback)
 * @param mobj
 * @return boolean
 */
    public boolean hasCollision(MobilObject mobj){
        boolean collision = false;
        int res = 0;
        for(Iterator<ObjectWithStates> objectsOnRegion
                                    =this.stateObjects.getObjectsNearMe(mobj)
                    ; objectsOnRegion.hasNext() && collision==false;
                    ){
                ObjectWithStates ob =objectsOnRegion.next();
                collision = ob.hasCollision(mobj, false);
                //System.out.println("Validate with "+ob.getName() );
        }
        return collision;
    }
}

